var arr = [5, 54, 7, 7, 76, 7, 874, 8, 4, 6];
var num = 6;

function swap(arr, i, j) {
  var temp = arr[i];
  arr[i] = arr[j];
  arr[j] = temp;
}
var i = 0;
var left = -1;
var right = arr.length;
while (i !== right) {
  if(arr[i] < num){
    left ++;
    swap(arr, i, left);
    i++
  }
  if(arr[i] === num) {
    i++;
  }
  if(arr[i] > num){
    right --;
    swap(arr, i, right);
  }
}
console.log(arr);


